<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>数组扁平化第一种方式 循环</title>
	</head>
	<body>
		<script>
			let arr = [0, [1, [2, 3, [4, [5, 6]], 7]], [8, 9]]
			function geyao(arr) {
				var show = []
				for (var i = 0; i < arr.length; i++) {
					//如果arr[i]是一个数组
					if (Array.isArray(arr[i])) {
                        //递归遍历arr[i]
						show.push.apply(show, geyao(arr[i]))
					} else {
						show.push(arr[i])
					}
				}
				return show
			}
            console.log(geyao(arr)) //[0,1,2,3,4,5,6,7,8,9]
		</script>
	</body>
</html>
